﻿namespace System.Lua.Serialization
{
    internal static class TypeExtensions
    {
        /// <summary>
        /// Determines whether the specified type should be serialized as a dictionary.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>
        /// 	<c>true</c> if the specified type should be serialized as a dictionary; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsDictionary(this Type type)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            return type.GetInterface("IDictionary`2") != null;
        }

        /// <summary>
        /// Determines whether the specified type should be serialized as a literal.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>
        /// 	<c>true</c> if the specified type should be serialized as a literal; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsLiteral(this Type type)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            return type.IsPrimitive || type == typeof(string) || type == typeof(DateTime);
        }
    }
}
